package com.app.qtjk.lsh.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.app.common.dataDictionary.DE.DE_APPVERSION_NUMBER;
import com.app.common.dataDictionary.DE.DE_PHONETYPE;
import com.app.common.dataDictionary.DE.DE_USERFEEDBACK_ID;
import com.app.common.dataDictionary.DE.DE_USERFEEDBACK_NR;
import com.app.common.dataDictionary.DE.DE_USERFEEDBACK_OPPTIME;
import com.app.common.dataDictionary.PO.TUserfeedbackPO;
import com.app.common.utils.ReqJsonUtil;
import com.css.sword.kernel.base.annotation.Service;
import com.css.sword.kernel.base.annotation.ServiceContainer;
import com.css.sword.kernel.base.persistence.IPersistenceService;
import com.css.sword.kernel.utils.SwordLogUtils;
import com.css.sword.kernel.utils.SwordPersistenceUtils;
import com.css.sword.kernel.utils.SwordSequenceUtils;
import com.css.sword.platform.web.event.IReqData;
import com.css.sword.platform.web.event.IResData;
import com.css.sword.platform.web.event.SwordReq;
import com.css.sword.platform.web.event.SwordRes;

@ServiceContainer
public class FeedbackService {

	private static SwordLogUtils log = SwordLogUtils
			.getLogger(FeedbackService.class);

	public FeedbackService() throws Exception {
		super();
	}

	/**
	 * 用户意见反馈
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Service(serviceName = "FeedbackService_userFeedback")
	public IResData userFeedback(IReqData req) throws Exception {

		log.debug("开始进入 FeedbackService_userFeedback 方法。");

		IPersistenceService dao = SwordPersistenceUtils.getPersistenceService();

		// IPageQueryDAO pdao=PageQueryUtils.getPageQueryDAO();

		IResData res = new SwordRes();
		HashMap commonMap = new HashMap();
		ArrayList commonList = new ArrayList();
		HashMap hashMap = new HashMap();
		try {
			// 获取前台post的数据
			String reqJson = ((SwordReq) req).getReqDataSet().getReqJson();
			Map<String, Object> postMap = ReqJsonUtil.json2map(reqJson);
			//前台传过来的三个参数
			String phonetype = (String)((ArrayList)postMap.get("phonetype")).get(0);
			String appversionNumber = (String)((ArrayList)postMap.get("appversionNumber")).get(0);
			String userfeedbackNr = (String)((ArrayList)postMap.get("userfeedbackNr")).get(0);
			try {
				TUserfeedbackPO tUserfeedbackPO = new TUserfeedbackPO();
				tUserfeedbackPO.setUserfeedbackId(new DE_USERFEEDBACK_ID(
						SwordSequenceUtils.generateRandomString()));
				tUserfeedbackPO.setPhonetype(new DE_PHONETYPE(phonetype));
				tUserfeedbackPO.setUserfeedbackNr(new DE_USERFEEDBACK_NR(
						userfeedbackNr));
				tUserfeedbackPO.setAppversionNumber(new DE_APPVERSION_NUMBER(appversionNumber));
				tUserfeedbackPO.setUserfeedbackOpptime(new DE_USERFEEDBACK_OPPTIME(
								new Date()));
				dao.insertPO(tUserfeedbackPO);
				hashMap.put("feedbackSuccess", "true");
				hashMap.put("returnStatus", "true");
				hashMap.put("msg", "成功返回，未出现异常！");
			} catch (Exception e) {
				log.debug("---------------用户意见反馈插入数据库发生异常！---------------");
				e.printStackTrace();
				hashMap.put("feedbackSuccess", "false");
				hashMap.put("returnStatus", "true");
				hashMap.put("msg", "用户意见反馈插入数据库操作出现异常！");
			}
			commonMap.put("commonData", hashMap);
			commonList.add(commonMap);
			res.addListWithDataName("returnData", commonList);
		} catch (Exception e) {
			log.debug("---------------系统发生异常！---------------");
			e.printStackTrace();
			hashMap.put("returnStatus", "false");
			hashMap.put("msg", "出现异常！");
			commonMap.put("commonData", hashMap);
			commonList.add(commonMap);
			res.addListWithDataName("returnData", commonList);
		}
		return res;

	}

}